package com.controller;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.servlet.ModelAndView;

import com.controller.base.BaseController;
import com.entity.ChanPing;
import com.entity.XinWenLanMu;
import com.entity.XinWenZiXun;
import com.entity.YongHu;
import com.entity.YongHuHangYe;
import com.service.ChanPingService;
import com.service.XinWenLanMuService;
import com.service.XinWenZiXunService;
import com.service.YongHuHangYeService;
import com.service.YongHuService;

@Controller
public class InsexpageController extends BaseController<Object>{
	@Autowired
	private YongHuHangYeService yhhyService;
	@Autowired
	private YongHuService yhService;
	@Autowired
	private XinWenZiXunService xwzxService;
	@Autowired
	private XinWenLanMuService xwlmService;
	@Autowired
	private ChanPingService cpService;
	
	
	//跳转主页
	@RequestMapping("/indexpage")
	public String index(HttpServletRequest request,Model md)throws Exception{
		HttpSession userSession = request.getSession();
		YongHu yh =(YongHu)userSession.getAttribute("USER");
		md.addAttribute("yhUser",yh);
		return "index";
	}
	
	@RequestMapping("/testcontent")
	public ModelAndView testcontent(){
		ModelAndView mv =  new ModelAndView();
		mv.setViewName("pages/content");
		return mv;
	}
	/**
	 * 跳转用户列表
	 * @param md
	 * @return
	 */
	@RequestMapping("/usertable")
	public ModelAndView usertable(){
		ModelAndView mv =  new ModelAndView();
		mv.setViewName("pages/usertable");
		return mv;
	}
	/**
	 * 跳转新闻资讯列表
	 * @param md
	 * @return
	 */
	@RequestMapping("/xwzxtable")
	public ModelAndView xwzxtable(){
		ModelAndView mv =  new ModelAndView();
		mv.setViewName("pages/xwzxtable");
		return mv;
	}
	/**
	 * 跳转新闻栏目列表
	 * @param md
	 * @return
	 */
	@RequestMapping("/xwlmtable")
	public ModelAndView xwlmtable(){
		ModelAndView mv =  new ModelAndView();
		mv.setViewName("pages/xwlmtable");
		return mv;
	}
	/**
	 * 跳转产品列表
	 * @param md
	 * @return
	 */
	@RequestMapping("/cptable")
	public ModelAndView cptable(){
		ModelAndView mv =  new ModelAndView();
		mv.setViewName("pages/cptable");
		return mv;
	}
	/**
	 * 跳转用户列表
	 * @param md
	 * @return
	 */
	@RequestMapping("/testuser")
	public ModelAndView testuser(){
		ModelAndView mv =  new ModelAndView();
		mv.setViewName("pages/usertable");
		return mv;
	}
	/**
	 * 跳转用户行业列表
	 * @param md
	 * @return
	 */
	@RequestMapping("/table")
	public ModelAndView table(){
		ModelAndView mv =  new ModelAndView();
		mv.setViewName("pages/tables");
		return mv;
	}
	/**
	 * 跳转添加用户行业页面
	 * @param md
	 * @return
	 */
	@RequestMapping("/addyhhy")
	public String addyhhy(Model md,String id){
		YongHuHangYe o = new YongHuHangYe();
		o.setId(id);
		List<YongHuHangYe> yhList = yhhyService.find(o);
		if(yhList.size()>0){
			o=yhList.get(0);
		}
		md.addAttribute("yhhy",o);
		return "pages/addyhhy";
	}
	/**
	 * 跳转更新用户行业页面
	 * @param md
	 * @return
	 */
	@RequestMapping("/updateyhhy")
	public String updateyhhy(Model md,String id){
		System.out.println("id"+id);
		YongHuHangYe o = new YongHuHangYe();
		o.setId(id);
		System.out.println(o);
		List<YongHuHangYe> yhList = yhhyService.find(o);
		if(yhList.size()>0){
			o=yhList.get(0);
		}
		md.addAttribute("yhhy",o);
		return "pages/updateyhhy";
	}
	/**
	 * 跳转添加用户页面
	 * @param md
	 * @return
	 */
	@RequestMapping("/addyh")
	public String addyh(Model md,String id){
		YongHu o = new YongHu();
		o.setId(id);
		List<YongHu> yhList = yhService.find(o);
		if(yhList.size()>0){
			o=yhList.get(0);
		}
		md.addAttribute("yh",o);
		return "pages/adduser";
	}
	/**
	 * 跳转更新用户页面
	 * @param md
	 * @return
	 */
	@RequestMapping("/updateyh")
	public String updateyh(Model md,String id){
		//System.out.println("yhid"+id);
		YongHu o = new YongHu();
		o.setId(id);
		//System.out.println("yh:"+o);
		List<YongHu> yhList = yhService.find(o);
		if(yhList.size()>0){
			o=yhList.get(0);
		}
		md.addAttribute("yh",o);
		return "pages/updateuser";
	}
	/**
	 * 跳转添加新闻资讯页面
	 * @param md
	 * @return
	 */
	@RequestMapping("/addxwzx")
	public String addxwzx(Model md,String id,HttpServletRequest request){
		HttpSession userSession = request.getSession();
		YongHu yh =(YongHu)userSession.getAttribute("USER");
		md.addAttribute("yhUser",yh);
		XinWenZiXun o = new XinWenZiXun();
		o.setId(id);
		List<XinWenZiXun> xwList = xwzxService.find(o);
		if(xwList.size()>0){
			o=xwList.get(0);
		}
		md.addAttribute("xw",o);
		return "pages/addxwzx";
	}
	/**
	 * 跳转更新新闻资讯页面
	 * @param md
	 * @return
	 */
	@RequestMapping("/updatexwzx")
	public String updatexwzx(Model md,String id){
		XinWenZiXun o = new XinWenZiXun();
		o.setId(id);
		System.out.println(o);
		List<XinWenZiXun> xwList = xwzxService.find(o);
		if(xwList.size()>0){
			o=xwList.get(0);
		}
		md.addAttribute("xw",o);
		return "pages/updatexwzx";
	}
	/**
	 * 跳转添加新闻栏目页面
	 * @param md
	 * @return
	 */
	@RequestMapping("/addxwlm")
	public String addxwlm(Model md,String id){
		XinWenLanMu o = new XinWenLanMu();
		o.setId(id);
		List<XinWenLanMu> xwList = xwlmService.find(o);
		if(xwList.size()>0){
			o=xwList.get(0);
		}
		md.addAttribute("xw",o);
		return "pages/addxwlm";
	}
	/**
	 * 跳转更新新闻栏目页面
	 * @param md
	 * @return
	 */
	@RequestMapping("/updatexwlm")
	public String updatexwlm(Model md,String id){
		XinWenLanMu o = new XinWenLanMu();
		o.setId(id);
		System.out.println(o);
		List<XinWenLanMu> xwList = xwlmService.find(o);
		if(xwList.size()>0){
			o=xwList.get(0);
		}
		md.addAttribute("xw",o);
		return "pages/updatexwlm";
	}
	/**
	 * 跳转添加产品页面
	 * @param md
	 * @return
	 */
	@RequestMapping("/addcp")
	public String addcp(Model md,String id){
		ChanPing o = new ChanPing();
		o.setId(id);
		List<ChanPing> cpList = cpService.find(o);
		if(cpList.size()>0){
			o=cpList.get(0);
		}
		md.addAttribute("cp",o);
		return "pages/addcp";
	}
	
}
